package com.android.meige.fragment.group;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.meige.R;
import com.android.meige.activity.BaseObject;
import com.android.meige.activity.GoodsStoreActivity;
import com.android.meige.fragment.BaseLazyFragment;
import com.android.meige.model.MainTabData;
import com.android.meige.model.detail.Banner;
import com.android.meige.model.detail.BrandGoodsListData;
import com.android.meige.model.group.CityGoodsData;
import com.android.meige.model.group.CityGoodsDataCallback;
import com.android.meige.model.group.MainThematicActivity_Insert;
import com.android.meige.model.group.MainThematicActivity_InsertCallback;
import com.android.meige.model.group.SameCityMainData;
import com.android.meige.model.group.SameCityMainDataCallback;
import com.android.meige.pojo.BannerUintPojo;
import com.android.meige.utils.ConstantsUrl;
import com.android.meige.utils.HttpUtils;
import com.android.meige.utils.JumpUtils;
import com.android.meige.utils.LoginState;
import com.android.meige.utils.ObjectUtils;
import com.android.meige.view.group.VRefreshLayout;
import com.android.meige.view.group.ViewPagerIndicator;
import com.android.meige.view.recycleview.CustomLoadMoreView;
import com.android.meige.view.recycleview.CustomRecycleView;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mcxtzhang.nestlistview.NestFullListView;
import com.mcxtzhang.nestlistview.NestFullListViewAdapter;
import com.mcxtzhang.nestlistview.NestFullViewHolder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;


/**
 * Created by Administrator on 2017/7/13.
 */

public class Fragment_SCMain_TabList extends BaseLazyFragment implements BaseQuickAdapter.RequestLoadMoreListener, View.OnClickListener {


    @BindView(R.id.listView)
    CustomRecycleView mRecyclerView;
    @BindView(R.id.swipe_refresh_layout)
    VRefreshLayout mRefreshLayout;
    @BindView(R.id.click_resetnetwork)
    LinearLayout clickResetnetwork;
    @BindView(R.id.progress)
    RelativeLayout progress;
    @BindView(R.id.no_data_tv)
    TextView noDataTv;
    @BindView(R.id.no_data)
    RelativeLayout noData;
    @BindView(R.id.progress_loading)
    FrameLayout progressLoading;

    private View rootView;
    private AdaptList adapter;
    private LayoutInflater inflater;
    private boolean networkConnected;
    private FragmentActivity mcontext;
    private int page;
    private ViewPagerIndicator viewPagerIndicator1;
    private BrandGoodsListData branddata = new BrandGoodsListData();
    private ArrayList<CityGoodsData.DataBean.ListBean> listdata = new ArrayList<>();
    private ArrayList<MainThematicActivity_Insert.DataBean.ListBean> ta_insert = new ArrayList<>();
    private NestFullListView sort_grid1;
    private NestFullListView sort_grid2;
    private ArrayList<MainTabData> griddata1 = new ArrayList<>();
    private ArrayList<MainTabData> griddata2 = new ArrayList<>();
    private ImageView thematic1;
    private ImageView thematic2;
    private ImageView thematic3;
    private ImageView thematic4;
    private ArrayList<Banner.Bannerdata> Bannerlist = new ArrayList<>();
    private static final String ARG_PARAM1 = "param1";
    private String id;
    //private View  fragment_head;
    private ViewPager bannerpager;
    private View inflate;
    private TextView refresh_textView;
    private LinearLayout llthematic1;
    private LinearLayout llthematic2;
    private View fragment_head;
    private MyReceiver receiver;
    private List<SameCityMainData.DataBean.AdBean> adList;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            id = getArguments().getString(ARG_PARAM1);
        }
    }

    public static Fragment_SCMain_TabList newInstance(String id) {
        Fragment_SCMain_TabList fragment = new Fragment_SCMain_TabList();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, id);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void initPrepare() {
        ReFreshData();
    }

    @Override
    protected void onInvisible() {

    }

    @Override
    protected void initData() {
        networkConnected = ObjectUtils.isNetworkConnected(getActivity());
        if (networkConnected) {
            page = 1;
            getMianThematic_Insert();
            GetSCMAIN();
            GetListData(page);
        } else {
            ObjectUtils.GetDataNet(clickResetnetwork, progress, 4);
        }

    }

    private LinearLayoutManager mLayoutManager;
    private GridLayoutManager mGridLayoutManager;

    @Override
    protected View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        this.inflater = inflater;
        networkConnected = ObjectUtils.isNetworkConnected(getActivity());
        rootView = inflater.inflate(R.layout.layout_recycle_scmainrefresh, container, false);
        ButterKnife.bind(this, rootView);
        mcontext = getActivity();
        //     mainTopBg.setVisibility(View.GONE);
        initUI();
        return rootView;
    }

    /**
     * 轮播图销毁开启
     */
    @Override
    public void onStart() {
        super.onStart();
        viewPagerIndicator1.setVisible(true);
    }

    @Override
    public void onPause() {
        super.onPause();
        viewPagerIndicator1.setVisible(false);
    }

    private void initUI() {
        //轮播图
        fragment_head = inflater.inflate(R.layout.scmain_fragment3_header_banner, null, false);
        bannerpager = (ViewPager) fragment_head.findViewById(R.id.bannerpager_fragment);
        viewPagerIndicator1 = (ViewPagerIndicator) fragment_head.findViewById(R.id.viewPagerIndicator1);
        viewPagerIndicator1.autoScroll(getChildFragmentManager(), bannerpager, 1);
        //分类+快报
        sort_grid1 = (NestFullListView) fragment_head.findViewById(R.id.main_fragment_grid_sort1);
        sort_grid2 = (NestFullListView) fragment_head.findViewById(R.id.main_fragment_grid_sort2);
        sort_grid1.setAdapter(new NestFullListViewAdapter<MainTabData>(R.layout.item_grid_fragment_sort, griddata1) {
            @Override
            public void onBind(int position, MainTabData testBean, NestFullViewHolder holder) {
                holder.setText(R.id.item_grid_fragment_sort_tv, testBean.getName());
                ObjectUtils.photo(mcontext, testBean.getImg(), ((ImageView) holder.getView(R.id.item_grid_fragment_sort_img)));
            }
        });
        sort_grid2.setAdapter(new NestFullListViewAdapter<MainTabData>(R.layout.item_grid_fragment_sort, griddata2) {
            @Override
            public void onBind(int position, MainTabData testBean, NestFullViewHolder holder) {
                holder.setText(R.id.item_grid_fragment_sort_tv, testBean.getName());
                ObjectUtils.photo(mcontext, testBean.getImg(), ((ImageView) holder.getView(R.id.item_grid_fragment_sort_img)));

            }
        });
        sort_grid1.setOnItemClickListener(new MainSortStartTo(griddata1));
        sort_grid2.setOnItemClickListener(new MainSortStartTo(griddata2));
        //四个专题
        llthematic1 = (LinearLayout) fragment_head.findViewById(R.id.ll_thematic1);
        llthematic2 = (LinearLayout) fragment_head.findViewById(R.id.ll_thematic2);
        thematic1 = (ImageView) fragment_head.findViewById(R.id.thematic1);
        thematic2 = (ImageView) fragment_head.findViewById(R.id.thematic2);
        thematic3 = (ImageView) fragment_head.findViewById(R.id.thematic3);
        thematic4 = (ImageView) fragment_head.findViewById(R.id.thematic4);
        thematic1.setOnClickListener(this);
        thematic2.setOnClickListener(this);
        thematic3.setOnClickListener(this);
        thematic4.setOnClickListener(this);
        mRecyclerView.removeAllViewsInLayout();
        mRecyclerView.removeAllViews();
        adapter = new AdaptList(mcontext, ta_insert, null, "0");
        adapter.addHeaderView(fragment_head);
        adapter.setLoadMoreView(new CustomLoadMoreView());
        adapter.setOnLoadMoreListener(this, mRecyclerView);
        mLayoutManager = new LinearLayoutManager(mcontext);
        mRecyclerView.setLayoutManager(mLayoutManager);
        mRecyclerView.setAdapter(adapter);
        mRecyclerView.GetToTop((ImageView) rootView.findViewById(R.id.top), 0);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter1, View view, int position) {
                CityGoodsData.DataBean.ListBean item = adapter.getItem(position);
                if (item != null) {
                    ObjectUtils.ToDetailActivity(mcontext, 1, item.getId(), "");
                }
            }
        });

        receiver = new MyReceiver();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(ConstantsUrl.INTENT_KEY.MAIN_GROUP_MEMBER_LOCATION_CHANGE);
        mcontext.registerReceiver(receiver, intentFilter);
    }

    /**
     * 分类跳转
     */
    class MainSortStartTo implements NestFullListView.OnItemClickListener {
        ArrayList<MainTabData> griddata;

        public MainSortStartTo(ArrayList<MainTabData> griddata) {
            this.griddata = griddata;
        }

        @Override
        public void onItemClick(NestFullListView nestFullListView, View view, int position) {

            MainTabData pojo = griddata.get(position);
            BannerUintPojo Apojo = new BannerUintPojo();
            Apojo.return_type = pojo.getAnurl();
            Apojo.title = pojo.getName();
            Apojo.id = pojo.getId();
            if (JumpUtils.jumpToEveryWhere(getActivity(), Apojo, Fragment_SCMain_TabList.this))
                return;

            switch (griddata.get(position).getName()) {
//                case "1":
//                    Intent intent_tab = new Intent(mcontext, MainTab.class);
//                    intent_tab.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TAB_SORT_SHOW_ID, 0);
//                    intent_tab.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TAB_SORT_SHOW_TYPE, 3);
//                    startActivity(intent_tab);
//                    break;
//                case "2":
//                    Intent intent_bd = new Intent(mcontext, BaseObject.class);
//                    intent_bd.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_TITLE,"品牌折扣");
//                    startActivity(intent_bd);
//                    break;
//                case "3":
//                    Intent intent_tabs = new Intent(mcontext, MainTab.class);
//                    intent_tabs.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TAB_SORT_SHOW_ID, 0);
//                    intent_tabs.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TAB_SORT_SHOW_TYPE, 8);
//                    startActivity(intent_tabs);
//                    break;
//                case "5":
//                    Intent intent_address = new Intent(mcontext, BaseObject.class);
//                    intent_address.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_TITLE, griddata.get(position).getName());
//                    startActivity(intent_address);
//                    break;
//                case "9":
//                    Intent intentss = new Intent (mcontext,BaseObject.class);
//                    intentss.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_TITLE,"店铺街");
//                    startActivity(intentss);
//                    break;
//                case "美国馆":
////                    Fragment_SeaAmoy a = (Fragment_SeaAmoy) getParentFragment();
////                    a.executeFromCountry(griddata3.get(position).getId());
//                    break;
                default:
                    Intent intent = new Intent(mcontext, GoodsStoreActivity.class);
                    intent.putExtra("storeid", griddata.get(position).getId());
                    startActivity(intent);
                    break;
            }
        }
    }

    private void ReFreshData() {
        if (mRefreshLayout != null) {
            mRefreshLayout.setBackgroundColor(Color.TRANSPARENT);
            mRefreshLayout.setAutoRefreshDuration(400);
            mRefreshLayout.setRatioOfHeaderHeightToReach(1.5f);
            mRefreshLayout.addOnRefreshListener(new VRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    networkConnected = ObjectUtils.isNetworkConnected(mcontext);
                    if (networkConnected) {
                        mRefreshLayout.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                mRefreshLayout.refreshComplete();
                                page = 1;
                                getMianThematic_Insert();
                                GetSCMAIN();
                                GetListData(page);
                            }
                        }, 1000);
                    } else {
                        ObjectUtils.toast(mcontext, "网络连接出现异常");
                    }
                }
            });
        }
    }

    @OnClick(R.id.click_resetnetwork_refresh)
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.click_resetnetwork_refresh:
                ObjectUtils.GetDataNet(clickResetnetwork, progress, 3);
                page = 1;
                getMianThematic_Insert();
                GetSCMAIN();
                GetListData(page);
                break;
            case R.id.thematic1:
                jumpFromAD(0);
                break;
            case R.id.thematic2:
                jumpFromAD(1);
                break;
            case R.id.thematic3:
                jumpFromAD(2);
                break;
            case R.id.thematic4:
                jumpFromAD(3);
                break;
        }
    }

    private void jumpFromAD(int position) {
        if (adList != null && adList.size() > position) {
            BannerUintPojo Apojo = new BannerUintPojo();
            SameCityMainData.DataBean.AdBean adBean = adList.get(position);
            Apojo.return_type = adBean.getAnurl();
            Apojo.title = adBean.getTitle();
            if (JumpUtils.jumpToEveryWhere(getActivity(), Apojo, Fragment_SCMain_TabList.this))
                return;
        }
    }

    @Override
    public void onLoadMoreRequested() {
        page++;
        GetListData(page);
    }

    /**
     * 专题活动插入信息
     */
    private void getMianThematic_Insert() {
        String address = ConstantsUrl.domain + ConstantsUrl.MAINTHMATIC_INSERT;
        HashMap<String, String> map = new HashMap<>();
        map.put("posid", "2");
        HttpUtils.get(address, map, new MainThematicActivity_InsertCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {

            }

            @Override
            public void onResponse(MainThematicActivity_Insert response, int id) {
                ta_insert.clear();
                if (response == null) {
                    return;
                }
                MainThematicActivity_Insert.DataBean data = response.getData();
                if (data != null && ObjectUtils.listHasData(data.getList())) {
                    ta_insert.addAll(data.getList());
                    mRecyclerView.setLayoutManager(mLayoutManager);
                    mRecyclerView.setAdapter(adapter);
                }
            }
        });
    }

    private void GetSCMAIN() {
        networkConnected = ObjectUtils.isNetworkConnected(getActivity());
        String address = ConstantsUrl.domain + ConstantsUrl.SAMECITYMAIN;
        HashMap<String, String> map = new HashMap<>();
        map.put("cid", id);
        if (networkConnected) {
            HttpUtils.get(address, map, new SameCityMainDataCallback() {

                @Override
                public void onError(Call call, Exception e, int id) {
                    adapter.removeHeaderView(fragment_head);
                }

                @Override
                public void onResponse(SameCityMainData response, int id) {
                    griddata1.clear();
                    griddata2.clear();
                    if (response == null) {
                        adapter.removeHeaderView(fragment_head);
                        return;
                    }
                    ObjectUtils.GetDataNet(clickResetnetwork, progress, 1);
                    if (response.getCode() == 0) {
                        Bannerlist = new ArrayList<>();
                        SameCityMainData.DataBean data = response.getData();
                        if (data != null) {
                            List<SameCityMainData.DataBean.ThumbBean> thumb = data.getThumb();
                            if (ObjectUtils.listHasData(thumb)) {
                                for (int i = 0; i < thumb.size(); i++) {
                                    Banner.Bannerdata bannerdata = new Banner.Bannerdata();
                                    bannerdata.setThumb(thumb.get(i).getPath());
                                    bannerdata.setLink(thumb.get(i).getAnurl());
                                    bannerdata.setPath("");
                                    Bannerlist.add(bannerdata);
                                }
                                viewPagerIndicator1.setViewPager(Bannerlist);
                                viewPagerIndicator1.setNotifyDataSetChanged();
                            }
                            int size1, size2;
                            List<SameCityMainData.DataBean.NavBean> nav = data.getNav();
                            if (ObjectUtils.listHasData(nav)) {
                                if (nav.size() > 5) {
                                    size1 = 5;
                                    size2 = nav.size() - 5;
                                } else {
                                    size1 = nav.size();
                                    size2 = 0;
                                }
                                for (int i = 0; i < size1; i++) {
                                    SameCityMainData.DataBean.NavBean navBean = nav.get(i);
                                    griddata1.add(new MainTabData(navBean.getTitle(), navBean.getId(), navBean.getImg().getPath(), navBean.getAnurl()));
                                }
                                for (int i = 5; i < size2; i++) {
                                    SameCityMainData.DataBean.NavBean navBean = nav.get(i);
                                    griddata2.add(new MainTabData(navBean.getTitle(), navBean.getId(), navBean.getImg().getPath(), navBean.getAnurl()));
                                }
                                sort_grid1.updateUI();
                                sort_grid2.updateUI();
                            }
                            adList = data.getAd();
                            if (adList != null && adList.size() > 1) {
                                llthematic1.setVisibility(View.VISIBLE);
                                ObjectUtils.photo2(mcontext, adList.get(0).getPath(), thematic1);
                                ObjectUtils.photo2(mcontext, adList.get(1).getPath(), thematic2);
                                if (adList.size() > 3) {
                                    llthematic2.setVisibility(View.VISIBLE);
                                    ObjectUtils.photo2(mcontext, adList.get(2).getPath(), thematic3);
                                    ObjectUtils.photo2(mcontext, adList.get(3).getPath(), thematic4);
                                }
                            }
                        } else {
                            adapter.removeHeaderView(fragment_head);
                        }
                    } else {
                        adapter.removeHeaderView(fragment_head);
                    }
                }
            });
        } else {
            ObjectUtils.toast(getActivity(), "网络连接出现异常");
        }
    }

    private void GetListData(final int page) {
        networkConnected = ObjectUtils.isNetworkConnected(mcontext);
        if (networkConnected) {
            String address = ConstantsUrl.domain + ConstantsUrl.CITYGOODS;
            String getid = LoginState.getInstance().getid(mcontext);
            String getpd = LoginState.getInstance().getpd(mcontext);
            HashMap<String, String> header = new HashMap<>();
            header.put("UID", getid);
            header.put("UPSW", getpd);
            HashMap<String, String> map = new HashMap<>();
            String zone = LoginState.getInstance().getUserInfo(mcontext, 2);
            map.put("page", page + "");
            map.put("zone", zone);
            map.put("cid", id);
            HttpUtils.get(address, header, map, new CityGoodsDataCallback() {

                @Override
                public void onError(Call call, Exception e, int id) {
                    ObjectUtils.GetDataNet(clickResetnetwork, progress, 2);
                }

                @Override
                public void onResponse(CityGoodsData response, int id) {
                    if (response == null) {
                        ObjectUtils.GetDataNet(clickResetnetwork, progress, 4);
                        return;
                    }
                    ObjectUtils.GetDataNet(clickResetnetwork, progress, 1);
                    if (response.getCode() == 0) {
                        CityGoodsData.DataBean data = response.getData();
                        if (data == null || !ObjectUtils.listHasData(data.getList())) {
                            if (page == 1) {
                                noData.setVisibility(View.VISIBLE);
                            } else {
                                adapter.loadMoreEnd();
                            }
                            return;
                        }
                        noData.setVisibility(View.GONE);
                        List<CityGoodsData.DataBean.ListBean> list = data.getList();
                        if (page == 1) {
                            adapter.setNewData(list);
                        } else {
                            adapter.addData(list);
                            adapter.loadMoreComplete();
                        }
                    } else {
                        if (page == 1) {
                            noData.setVisibility(View.VISIBLE);
                        } else {
                            adapter.loadMoreFail();
                            ObjectUtils.toast(mcontext, response.getMsg());
                        }
                    }
                }
            });
        } else {
            if (page == 1) {
                ObjectUtils.GetDataNet(clickResetnetwork, progress, 2);
            }
            ObjectUtils.toast(mcontext, "网络连接出现异常");
            adapter.loadMoreFail();
        }
    }

    public class AdaptList extends BaseMultiItemQuickAdapter<CityGoodsData.DataBean.ListBean, BaseViewHolder> {
        private String type;
        private FragmentActivity mcontext;
        private ArrayList<MainThematicActivity_Insert.DataBean.ListBean> ta_insert;
        private int limitposition;

        public AdaptList(Context context, ArrayList<CityGoodsData.DataBean.ListBean> data, String type) {
            super(data);
            addItemType(ConstantsUrl.BRANDDISCOUNTMAINITEMTYPE, R.layout.item_list_main);
        }

        public AdaptList(FragmentActivity context, ArrayList<MainThematicActivity_Insert.DataBean.ListBean> ta_insert, List<CityGoodsData.DataBean.ListBean> data, String type) {
            super(data);
            //  this.datasize = data.size();
            this.mcontext = context;
            this.type = type;
            this.ta_insert = ta_insert;
            addItemType(ConstantsUrl.BRANDDISCOUNTMAINITEMTYPE, R.layout.item_list_main);
        }

        @Override
        protected void convert(BaseViewHolder holder, final CityGoodsData.DataBean.ListBean mainlistdata) {
            switch (holder.getItemViewType()) {
                case ConstantsUrl.BRANDDISCOUNTMAINITEMTYPE:
                    holder.setVisible(R.id.main_list_item_go_kai, true);
                    ((TextView) holder.getView(R.id.item_list_sort_aa_before)).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                    ObjectUtils.photo2(mContext, mainlistdata.getThumb(), ((ImageView) holder.getView(R.id.main_list_item_image)));
                    holder.setText(R.id.main_list_item_tuannumber, mainlistdata.getTeam_num() + "人团");
                    holder.setText(R.id.ll_start_soon_num, mainlistdata.getTeam_num() + "人团");
                    holder.setText(R.id.ll_free_num, mainlistdata.getTeam_num() + "人团");
                    int sell = mainlistdata.getSell();
                    if (sell > 0) {
                        holder.setText(R.id.main_list_item_alltuannumber2, "已团" + sell + "件");
                    }
                    holder.setText(R.id.main_list_item_title, mainlistdata.getName());
                    String price1 = mainlistdata.getTeam_price();
                    SpannableString msp = new SpannableString("￥" + price1);
                    msp.setSpan(new AbsoluteSizeSpan(13, true), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    //     holder.setText(R.id.main_list_item_money_after, msp);
                    /**
                     * 插入专题活动
                     */
                    final int taposition = holder.getAdapterPosition() + 1;
                    limitposition = 4 * ta_insert.size();
                    if (mcontext instanceof FragmentActivity) {
                        if (taposition % 4 == 0 && taposition <= limitposition) {

                            holder.getView(R.id.ll_tainsert).setVisibility(View.VISIBLE);
                            holder.getView(R.id.progress_hot).setVisibility(View.INVISIBLE);
                            TextView more_tv = (TextView) holder.getView(R.id.more_tv);
                            //水平滚动列表
                            NestFullListView tabrow = (NestFullListView) holder.getView(R.id.grid);
                            //        //动态设置选项卡宽度，超过2个可以滑动查看
                            DisplayMetrics metrics = new DisplayMetrics();
                            mcontext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
                            int width = (int) (metrics.widthPixels / 2.5);
                            final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, LinearLayout.LayoutParams.MATCH_PARENT);
                            tabrow.setAdapter(new NestFullListViewAdapter<MainThematicActivity_Insert.DataBean.ListBean.ApplyBean>(R.layout.list_main_hor_adapter, ta_insert.get(taposition / 4 - 1).getApply_list()) {
                                @Override
                                public void onBind(int position, MainThematicActivity_Insert.DataBean.ListBean.ApplyBean testBean, NestFullViewHolder holder) {
                                    (holder.getView(R.id.item_grid_detail_like_ll)).setLayoutParams(params);
                                    ((TextView) holder.getView(R.id.item_grid_detail_like_number_before)).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
                                    String price1 = testBean.getTeam_price();
                                    SpannableString msp = new SpannableString("￥" + price1);
                                    msp.setSpan(new AbsoluteSizeSpan(10, true), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                                    ((TextView) holder.getView(R.id.item_grid_detail_like_number_after)).setText(msp);
                                    holder.setText(R.id.item_grid_detail_like_number_before, "￥" + testBean.getPrice());
                                    holder.setText(R.id.item_grid_detail_like_title, testBean.getName());
                                    ObjectUtils.photo2(mcontext, testBean.getImg_cover(), ((ImageView) holder.getView(R.id.item_grid_detail_like_img)));

                                }
                            });

                            tabrow.setOnItemClickListener(new NestFullListView.OnItemClickListener() {
                                @Override
                                public void onItemClick(NestFullListView nestFullListView, View view, int pos) {
                                    // ObjectUtils.ToDetailActivity(mcontext, 1, ta_insert.get(taposition / 4 - 1).getApply_list().get(pos).getSid(), "");
                                }
                            });
                            more_tv.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    Intent intent = new Intent(mcontext, BaseObject.class);
                                    intent.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_NEED_ID, ta_insert.get(taposition / 3 - 1).getId());
                                    intent.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_TITLE, "专题活动");
                                    mcontext.startActivity(intent);
                                }
                            });

                        } else {
                            holder.getView(R.id.ll_tainsert).setVisibility(View.GONE);
                        }
                    }
                    break;
            }
        }
    }

    private class MyReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (rootView != null) {
                initData();
            }
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mcontext.unregisterReceiver(receiver);
    }
}
